package org.hxyjs.service.impl;

import org.hxyjs.dao.MatchOddsRecordDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.MatchOddsRecord;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.MatchOddsRecordService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("MatchOddsRecordService")
public class MatchOddsRecordServiceImpl implements MatchOddsRecordService {
    @Resource
    MatchOddsRecordDao matchOddsRecordDao;
    @Override
    public DTO<MatchOddsRecord> getAllMatchOddsRecords()  throws Exception{
        List<MatchOddsRecord> matchOddsRecords = matchOddsRecordDao.getAllMatchOddsRecords();
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(matchOddsRecords).isPresent()? MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<MatchOddsRecord>(messageEnum.getCode(),messageEnum.getMessage(),matchOddsRecords);
    }

    @Override
    public DTO<MatchOddsRecord> deleteMatchOddsRecordByMorno(String morno)  throws Exception{
        Integer result = matchOddsRecordDao.deleteMatchOddsRecordByMorno(morno);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETEADMINSUCCESS:MessageEnum.DELETEADMINFAIL;
        return new DTO<MatchOddsRecord>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<MatchOddsRecord> updateMatchOddsRecordByMorno(MatchOddsRecord matchOddsRecord) throws Exception {
        Integer result = matchOddsRecordDao.updateMatchOddsRecordByMorno(matchOddsRecord);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATEADMINSUCCESS:MessageEnum.UPDATEADMINFAIL;
        return new DTO<MatchOddsRecord>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<MatchOddsRecord> addMatchOddsRecord(MatchOddsRecord matchOddsRecord) throws Exception {
        Integer result = matchOddsRecordDao.addMatchOddsRecord(matchOddsRecord);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.ADDADMINSUCCESS:MessageEnum.ADDADMINFAIL;
        return new DTO<MatchOddsRecord>(messageEnum.getCode(),messageEnum.getMessage());
    }

    /**
     * 学生选课成功 学生成绩加1分，从选课信息中可以获得学生的学号就能查询出学生原来的成绩
     * @param
     * @return
     * @throws Exception
     */
    @Override
    public DTO<MatchOddsRecord> getMatchOddsRecordByMorno(String morno)  throws Exception{
        MatchOddsRecord matchOddsRecords = matchOddsRecordDao.getMatchOddsRecordByMorno(morno);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(matchOddsRecords).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<MatchOddsRecord>(messageEnum.getCode(),messageEnum.getMessage(),matchOddsRecords);
    }
    /**
     * 学生选课成功 学生成绩加1分，从选课信息中可以获得学生的学号就能查询出学生原来的成绩
     * @param
     * @return
     * @throws Exception
     */
    @Cacheable(value = "myCache",key = "#cacheId")
    @Override
    public DTO<MatchOddsRecord> getMatchOddsRecordByPage(PageInfo pageInfo ,String cacheId) throws Exception {
        List<MatchOddsRecord> matchOddsRecords = matchOddsRecordDao.getMatchOddsRecordByPage(pageInfo);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(matchOddsRecords).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<MatchOddsRecord>(messageEnum.getCode(),messageEnum.getMessage(),matchOddsRecords,pageInfo);
    }
    
    public DTO<MatchOddsRecord> getMatchOddsRecordByPage(PageInfo pageInfo) throws Exception {
        List<MatchOddsRecord> matchOddsRecords = matchOddsRecordDao.getMatchOddsRecordByPage(pageInfo);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(matchOddsRecords).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<MatchOddsRecord>(messageEnum.getCode(),messageEnum.getMessage(),matchOddsRecords,pageInfo);
    }

//    @Override
//    public DTO<MatchOddsRecord> selectMatchOddsRecordWithorderAndUser(String morno) throws Exception {
//        MatchOddsRecord matchOddsRecords = matchOddsRecordDao.selectMatchOddsRecordWithorderAndUser(morno);
//        //isPresent表示判断不为空成立则dto为？与：之间的对象
//        MessageEnum messageEnum  = Optional.ofNullable(matchOddsRecords).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
//        return new DTO<MatchOddsRecord>(messageEnum.getCode(),messageEnum.getMessage(),matchOddsRecords);
//    }


}
